<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Guideline: Test Driven Development</title>
<meta name="uma.type" content="Guideline">
<meta name="uma.name" content="test_driven_development">
<meta name="uma.presentationName" content="Test Driven Development">
<meta name="element_type" content="other">
<meta name="filetype" content="description">
<meta name="role" content="">
<link rel="StyleSheet" href="./../../../css/default.css" type="text/css">
<script src="./../../../scripts/ContentPageResource.js" type="text/javascript" language="JavaScript"></script><script src="./../../../scripts/ContentPageSection.js" type="text/javascript" language="JavaScript"></script><script src="./../../../scripts/ContentPageSubSection.js" type="text/javascript" language="JavaScript"></script><script src="./../../../scripts/ContentPageToolbar.js" type="text/javascript" language="JavaScript"></script><script src="./../../../scripts/contentPage.js" type="text/javascript" language="JavaScript"></script><script type="text/javascript" language="JavaScript">
					var backPath = './../../../';
					var imgPath = './../../../images/';
					var nodeInfo=null;
					contentPage.preload(imgPath, backPath, nodeInfo,  '', false, false, false);
				</script>
</head>
<body>
<div id="breadcrumbs"></div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top"><a name="Top"></a>
<div id="page-guid" value="_5s_DUJ03EdyQ3oTO93enUw"></div>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td class="pageTitle" nowrap="true">Guideline: Test Driven Development</td><td width="100%">
<div align="right" id="contentPageToolbar"></div>
</td><td width="100%" class="expandCollapseLink" align="right"><a name="mainIndex" href="./../../../index.htm"></a><script language="JavaScript" type="text/javascript" src="./../../../scripts/treebrowser.js"></script></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="pageTitleSeparator"><img src="./../../../images/shim.gif" alt="" title="" height="1"></td>
</tr>
</table>
<div class="overview">
<table width="97%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50"><img src="./../../../images/guidance.gif" alt="" title=""></td><td>
<table class="overviewTable" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">This guideline explains how to apply test driven design.</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div class="sectionHeading">Relationships</div>
<div class="sectionContent">
<table class="sectionTable" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<th class="sectionTableHeading" scope="row">Related Elements</th><td class="sectionTableCell">
<ul>
<li>
<a href="./../../../core.tech.common.extend_supp/guidances/concepts/developer_testing_FEBDAED6.html" guid="_ADwlAJRtEdyrdaw_xGakyw">Developer Testing</a>
</li>
<li>
<a href="./../../../core.tech.common.extend_supp/guidances/guidelines/developer_testing_9974EA47.html" guid="_ByOd4O6pEduvoopEslG-4g">Developer Testing</a>
</li>
<li>
<a href="./../../../core.tech.common.extend_supp/guidances/guidelines/refactoring_F3D63EBD.html" guid="_YNx2sJ05EdyQ3oTO93enUw">Refactoring</a>
</li>
</ul>
</td>
</tr>
</table>
</div>
<div class="sectionHeading">Main Description</div>
<div class="sectionContent">
<table class="sectionTable" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td class="sectionTableSingleCell"><h3>
    Introduction
</h3>
<p>
    With Test Driven Development (TDD) you do detailed design in a just-in-time (JIT) manner via writing a single test
    before writing just enough production code to fulfill that test. When you have new functionality to add to your system,
    perform the following steps:
</p>
<ol>
    <li>
        <strong>Quickly add a developer test</strong>. You need just enough implementation code to fail.&nbsp; For example,
        a new method about to be added to a class could be created that just throws a fatal exception.
    </li>
    <li>
        <strong>Run your tests</strong>. You will typically run the complete test suite, although for sake of speed you may
        decide to run only a subset. The goal is to ensure that the new test does in fact fail.
    </li>
    <li>
        <strong>Update your production code</strong>. The goal is to add just enough functionality so that&nbsp;the code
        passes the new test.&nbsp;
    </li>
    <li>
        <strong>Run your test suite again</strong>. If the tests fail you need to update your functional code and retest.
        Once the tests pass, start over.
    </li>
</ol><br />
<p>
    <img height="600" alt="Test First Design Flow" src="./../../../practice.tech.test_driven_development.base/guidances/guidelines/./resources/test_first_design.jpg" width="294" />
</p>
<h4>
    Why TDD?
</h4>
<p>
    A significant advantage of TDD is that it enables you to take small steps when writing software, which is not only
    safer it is also far more productive than writing code in large steps. For example, assume you add some new functional
    code, compile, and test it. Chances are pretty good that your tests will be broken by defects that exist in the new
    code. It is much easier to find, and then fix, those defects if you've written five new lines of code than fifty lines.
    The implication is that the faster your compiler and regression test suite, the more attractive it is to proceed in
    smaller and smaller steps.
</p>
<p>
    There are other common testing strategies (listed here in order of effectiveness).
</p>
<ol>
    <li>
        <strong>Write several tests first</strong>. This is a variant of TDD where you write more than one test before
        writing just enough production code to fulfill those tests. The advantage is that you don't need to build your
        system as often, potentially saving time. It has the disadvantage that you will write more production code at once,
        increasing the difficulty of finding the cause of new bugs.
    </li>
    <li>
        <strong>Test after the fact</strong>. With this approach you write some production code then you write enough
        testing code to validate it. This has the advantage that you're at least still validating the code but has the
        disadvantage that you lose the design benefit inherent in writing the testing code first.
    </li>
</ol>
<p>
    An underlying assumption of TFD is that a unit-testing framework is available. Agile software developers often use the
    xUnit family of open source tools, such as <a href="http://www.junit.org/"><strong><u><font     color="#0000ff">JUnit</font></u></strong></a> or <a href="http://www.vbunit.org/"><strong><u><font     color="#0000ff">VBUnit</font></u></strong></a>, although commercial tools are also viable options.
</p></td>
</tr>
</table>
</div>
<div class="sectionHeading">More Information</div>
<div class="sectionContent">
<table class="sectionTable" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<th class="sectionTableHeading" scope="row">Concepts</th><td class="sectionTableCell">
<ul>
<li>
<a href="./../../../core.tech.common.extend_supp/guidances/concepts/developer_testing_FEBDAED6.html" guid="_ADwlAJRtEdyrdaw_xGakyw">Developer Testing</a>
</li>
<li>
<a href="./../../../core.tech.common.extend_supp/guidances/concepts/refactoring_1B63BA3B.html" guid="_Poc7IPDzEdqYgerqi84oCA">Refactoring</a>
</li>
</ul>
</td>
</tr>
<tr valign="top">
<th class="sectionTableHeading" scope="row">Guidelines</th><td class="sectionTableCell">
<ul>
<li>
<a href="./../../../core.tech.common.extend_supp/guidances/guidelines/developer_testing_9974EA47.html" guid="_ByOd4O6pEduvoopEslG-4g">Developer Testing</a>
</li>
<li>
<a href="./../../../core.tech.common.extend_supp/guidances/guidelines/refactoring_F3D63EBD.html" guid="_YNx2sJ05EdyQ3oTO93enUw">Refactoring</a>
</li>
</ul>
</td>
</tr>
</table>
</div>
<table class="copyright" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="copyright"><p> This program and the accompanying materials are made available under the<br />
  <a href="http://www.eclipse.org/org/documents/epl-v10.php" target="_blank">Eclipse 
  Public License V1.0</a>, which accompanies this distribution. </p><p/><p> <a class="elementLink" href="./../../../core.default.release_copyright.base/guidances/supportingmaterials/openup_copyright_C3031062.html" guid="_UaGfECcTEduSX6N2jUafGA">OpenUP Copyright</a></p></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
<script type="text/javascript" language="JavaScript">
				contentPage.onload();
			</script>
</html>
